package com.atguigu.service.impl;

import com.atguigu.mapper.HospitalSetMapper;
import com.atguigu.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Override
    public Map<String, Object> selectPage(Long page, Long limit) {
        Page<HospitalSet> pageParam = new Page<>(page,limit);
        baseMapper.selectPage(pageParam,null);
        List<HospitalSet> records = pageParam.getRecords();
        long total = pageParam.getTotal();//总记录数====前端使用该参数做分页控件
        Map<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("rows",records);
        return map;
    }

    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(queryWrapper);
        return  hospitalSet.getSignKey();
    }

    @Override
    public String findApiUrl(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(queryWrapper);
        return  hospitalSet.getApiUrl();
    }
}
